import {
  VuexModule,
  Module,
  Mutation,
  Action,
  getModule
} from 'vuex-module-decorators'
import store from '@/store'
import { getRoleList, getUserList } from '@/api/selectList'

export interface Select {
  label: string
  value: string | number
}

export interface SelectListState {
  roleList: Select[]
  bdList: Select[]
}

@Module({ dynamic: true, store, name: 'select' })
class SelectList extends VuexModule implements SelectListState {
  roleList: Select[] = []
  bdList: Select[] = []

  @Mutation
  setRoleList(list: Select[]) {
    this.roleList = list
  }

  @Mutation
  setBdUserList(list: Select[]) {
    this.bdList = list
  }

  @Action({ commit: 'setRoleList' })
  async fetchRoleList() {
    const res = await getRoleList()
    return res.data
  }

  @Action({ commit: 'setBdUserList' })
  async fetchBdList() {
    const res = await getUserList(104)
    return res.data
  }
}

export const SelectListModule = getModule(SelectList)
